# Contributor: Matthias Ahouansou <matthias@ahouansou.cz>
# Maintainer: Matthias Ahouansou <matthias@ahouansou.cz>
pkgname=mautrix-discord
pkgver=0.6.5
pkgrel=3
pkgdesc="Matrix-Discord puppeting bridge"
url="https://go.mau.fi/mautrix-discord/"
arch="all"
license="AGPL-3.0-or-later"
depends="lottieconverter"
makedepends="go olm-dev sqlite-dev"
install="$pkgname.pre-install"
subpackages="$pkgname-openrc $pkgname-doc"
source="$pkgname-$pkgver.tar.gz::https://github.com/mautrix/discord/archive/v$pkgver.tar.gz
	mautrix-discord.initd
	mautrix-discord.confd
	default-log-dir.patch
"
builddir="$srcdir/discord-$pkgver"
options="net"

export GOFLAGS="$GOFLAGS -tags=libsqlite3"
export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	export CGO_CFLAGS="$CFLAGS"
	export CGO_LDFLAGS="$LDFLAGS"
	go build
}

check() {
	go test -v ./...
}

package() {
	install -Dm755 mautrix-discord \
		-t "$pkgdir"/usr/bin/
	install -Dm644 example-config.yaml \
		-t "$pkgdir"/etc/mautrix-discord/

	install -Dm755 "$srcdir"/mautrix-discord.initd \
		"$pkgdir"/etc/init.d/mautrix-discord
	install -Dm644 "$srcdir"/mautrix-discord.confd \
		"$pkgdir"/etc/conf.d/mautrix-discord

	install -Dm 644 LICENSE "$pkgdir"/usr/share/licenses/"$pkgname"/LICENSE
}

sha512sums="
b52bc3a963c52970a6af334e985b959efc04e3181cac6d2c1f404b06ee94d19a2ed4a7edfcbe2248eb2ee5196e19f917c9451326593fc5b95724bdc7dd6fd936  mautrix-discord-0.6.5.tar.gz
1d5dd1ab6fb9ef88466ea60af8fa271e2f46d9ec71f0d0404c92edab70f4fc348a9f9ba696d2e90eb4a21436070f6ba2cc80631a025214829e06a7124a43ccbd  mautrix-discord.initd
46c472289880a631389dbc7f40062858f7a11e2987f1183cb16d426aa50f57d4b57e4857e4f9852b1c930fc03ccf304bcd27a452681a570e97ec8174808cbf01  mautrix-discord.confd
f2317ccd91959c2d6b6937ab09bbcb5e2472847c5b880c4a37a4dd96784705a503a5cfcb183017656d716dfceabbc55c33d1083f1cb26c7964bf6dd4dd57f364  default-log-dir.patch
"
